package com.itheima.clientAndService02;

import java.io.*;
import java.net.Socket;

public class ClientClass {
    public static void main(String[] args) throws IOException {
        //创建客户端传输对象，并将其连接到指定的地址上
        Socket s = new Socket("127.0.0.1",10012);
        //创建缓冲字节输入流对象，读取指定目录文件
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("day16\\aaa\\a.jpg"));
        //创建缓冲字节输出流对象（Socket创建字节流对象）
        BufferedOutputStream bos = new BufferedOutputStream(s.getOutputStream());
        //字节读取文件
        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }
        //网络传输结束，必须刷新
        bos.flush();
        //传输结束标记
        s.shutdownOutput();

        //创建字符缓冲输入流对象，接收反馈消息
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        //字符读取数据
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }

        //释放资源
        bis.close();
        s.close();
    }
}
